package org.obs.core.hibernate.operations;

import org.hibernate.Session;
import org.obs.core.HibernateOperation;
import org.obs.domain.User;
import org.obs.domain.UserBlog;
import org.obs.form.CreateUserForm;

public class CreateUserOperation implements HibernateOperation <Object>{

	private CreateUserForm form;

	public CreateUserOperation(CreateUserForm form) {
		this.form = form;
	}

	public User execute(Session session) {
		User user = new User();
		user.setEmail(form.getEmail());
		user.setPassword(form.getPassword());
		user.setNick(form.getNick());
		
		UserBlog blog = new UserBlog();
		blog.setTitle("Blog");
		user.setBlog(blog);

		session.save(blog);
		session.save(user);
		return user;
	}

}
